package com.evil.application.command.scope;

import com.evil.common.application.enums.permission.ApplicationPermissionTypeEnum;
import com.evil.common.core.util.StreamUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;

/**
 * 控件选择范围命令
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
public class ControlSelScopeCommand extends HashMap<ApplicationPermissionTypeEnum, BiFunction<Map<Integer, List<Long>>, Map.Entry<Integer, List<Long>>, List<Long>>> {

    public List<Long> actionKey(Map<Integer, List<Long>> dynamicTypeTargetsMap, Map.Entry<Integer, List<Long>> entry) {
        ApplicationPermissionTypeEnum typeEnum = ApplicationPermissionTypeEnum.isExistById(entry.getKey());
        return this.containsKey(typeEnum) ? this.get(typeEnum).apply(dynamicTypeTargetsMap, entry) : new ArrayList<>();
    }

    public void putDefault(ApplicationPermissionTypeEnum typeEnum, Map<Integer, List<Long>> dynamicTypeTargetsMap) {
        this.put(typeEnum, (map, entry) -> StreamUtil.filter(dynamicTypeTargetsMap.get(entry.getKey()), e -> !entry.getValue().contains(e)));
    }
}
